<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>


	<script>
		var arr1 = [2, 8, 7, '2', 3, 8, 6, 2];

		/*function uniq2(arr) {
			var tmpArr = [], i, len = arr.length;

			for (i=0; i<len; i++) {
				if (!isInArray(tmpArr, arr[i])) { // 不在数组中
					tmpArr.push(arr[i]);
				}
			}

			return tmpArr;
		}

		function isInArray(arr, item) {
			var i, len = arr.length;
			for (i=0; i<len; i++) {
				if (arr[i] === item) {
					return true;
				}
			}
			return false;
		}*/

		function uniq(arr) {
			var obj = {}, i=0, len = arr.length, key;

			for (; i<len; i++) {
				obj[arr[i]] = arr[i];
			}

			// console.log(obj)

			arr.length = 0;

			for (key in obj) {
				arr.push(obj[key]);
			}

			return arr;
		}

		var r = uniq(arr1);

		console.log(r);
	</script>
</body>
</html>